<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="账单编码" prop="billNum">
        <el-input
          v-model="queryParams.billNum"
          placeholder="请输入账单编码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="账单状态" prop="billState">
        <el-select clearable
                   v-model="queryParams.billState"
                   placeholder="请选择账单状态">
          <el-option label="执行中"
                     value="0"></el-option>
          <el-option label="已作废"
                     value="1"></el-option>
          <el-option label="已过期"
                     value="2"></el-option>

        </el-select>
      </el-form-item>

<!--      <el-form-item label="结清状态" prop="payState">
        <el-select clearable
                   v-model="queryParams.payState"
                   placeholder="请选择结清状态">
          <el-option label="待支付"
                     value="0"></el-option>
          <el-option label="部分支付"
                     value="1"></el-option>
          <el-option label="已支付"
                     value="2"></el-option>
        </el-select>
      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['life:feApartmentCancelBill:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['life:feApartmentCancelBill:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['life:feApartmentCancelBill:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['life:feApartmentCancelBill:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-tabs v-model="tabActiveName" @tab-click="tabClick">
      <el-tab-pane label="未支付" name="1"></el-tab-pane>
      <el-tab-pane label="部分支付" name="2"></el-tab-pane>
      <el-tab-pane label="已支付" name="3"></el-tab-pane>
      <el-tab-pane label="全部" name="4"></el-tab-pane>
    </el-tabs>

    <el-table v-loading="loading" :data="feApartmentCancelBillList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!--<el-table-column label="序号" align="center" prop="id" />-->
      <el-table-column label="退租记录id" align="center" prop="cancelId" />
      <el-table-column label="账单编码" align="center" prop="billNum" />
      <el-table-column label="账单金额" align="center" prop="billMoney" />
      <el-table-column label="账单生效日期" align="center" prop="effectiveDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.effectiveDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <!--(0待确认，1欠费中，2已缴费)-->
      <el-table-column label="账单状态" align="center" prop="billState" >
        <template slot-scope="scope">
          <span>{{
              scope.row.billState === "0"
                ? "执行中"
                : scope.row.billState === "1"
                  ? "已作废"
                  : scope.row.billState === "2"
                    ? "已过期"
                    : "暂无"
            }}</span>
        </template>
      </el-table-column>
      <el-table-column label="违约金" align="center" prop="fine" />
      <el-table-column label="总计" align="center" prop="total" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="实收违约金" align="center" prop="actualFine" />
      <el-table-column label="实收金额" align="center" prop="actualAmount" />
      <!--(0待支付，1部分支付，2已支付)-->
      <el-table-column label="结清状态" align="center" prop="payState" >
        <template slot-scope="scope">
          <span>{{
              scope.row.payState === "0"
                ? "待支付"
                : scope.row.payState === "1"
                  ? "部分支付"
                  : scope.row.payState === "2"
                    ? "已支付"
                    : "暂无"
            }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['life:feApartmentCancelBill:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['life:feApartmentCancelBill:remove']"
          >删除</el-button>
          <el-button size="mini"
                     type="text"
                     icon="el-icon-document-checked"
                     @click="showReOkFn(scope.row)"
                     v-hasPermi="['life:feApartmentCancelBill:reOk']">账单确认
          </el-button>
          <el-button size="mini"
                     type="text"
                     icon="el-icon-document-checked"
                     @click="handleZhifu(scope.row)"
                     v-hasPermi="['life:feApartmentCancelBill:pay']">收款
          </el-button>
          <el-button size="mini"
                     type="text"
                     icon="el-icon-document-delete"
                     @click="handleDamagesDetail(scope.row)"
                     v-hasPermi="['life:feBill:detail']">缴费明细
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改公寓退租账单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="退租记录id" prop="cancelId">
          <el-input v-model="form.cancelId" placeholder="请输入退租记录id" />
        </el-form-item>
        <el-form-item label="账单编码" prop="billNum">
          <el-input v-model="form.billNum" placeholder="请输入账单编码" />
        </el-form-item>
        <el-form-item label="账单金额" prop="billMoney">
          <el-input v-model="form.billMoney" placeholder="请输入账单金额" />
        </el-form-item>
        <el-form-item label="账单生效日期" prop="effectiveDate">
          <el-date-picker clearable size="small"
            v-model="form.effectiveDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择账单生效日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="账单状态" prop="billState">
          <el-select clearable
                     v-model="form.billState"
                     placeholder="请选择账单状态">
            <el-option label="执行中"
                       value="0"></el-option>
            <el-option label="已作废"
                       value="1"></el-option>
            <el-option label="已过期"
                       value="2"></el-option>

          </el-select>
        </el-form-item>
        <el-form-item label="违约金" prop="fine">
          <el-input v-model="form.fine" placeholder="请输入违约金" />
        </el-form-item>
        <el-form-item label="总计" prop="total">
          <el-input v-model="form.total" placeholder="请输入总计" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="实收违约金" prop="actualFine">
          <el-input v-model="form.actualFine" placeholder="请输入实收违约金" />
        </el-form-item>
        <el-form-item label="实收金额" prop="actualAmount">
          <el-input v-model="form.actualAmount" placeholder="请输入实收金额" />
        </el-form-item>
        <el-form-item label="结清状态" prop="payState">
          <el-select clearable
                     v-model="form.payState"
                     placeholder="请选择结清状态">
            <el-option label="待支付"
                       value="0"></el-option>
            <el-option label="部分支付"
                       value="1"></el-option>
            <el-option label="已支付"
                       value="2"></el-option>

          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listFeApartmentCancelBill, getFeApartmentCancelBill, delFeApartmentCancelBill, addFeApartmentCancelBill,
  updateFeApartmentCancelBill }from "@/api/smartParks/operatingFee/feApartmentCancelBill";

export default {
  name: "FeApartmentCancelBill",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      tabActiveName: '1',
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 公寓退租账单表格数据
      feApartmentCancelBillList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        cancelId: null,
        billNum: null,
        billMoney: null,
        effectiveDate: null,
        billState: null,
        fine: null,
        total: null,
        actualFine: null,
        actualAmount: null,
        payState: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询公寓退租账单列表 */
    getList() {
      this.loading = true;
      listFeApartmentCancelBill(this.queryParams).then(response => {
        this.feApartmentCancelBillList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        cancelId: null,
        billNum: null,
        billMoney: null,
        effectiveDate: null,
        billState: null,
        fine: null,
        total: null,
        remark: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        actualFine: null,
        actualAmount: null,
        payState: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加公寓退租账单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getFeApartmentCancelBill(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改公寓退租账单";
      });
    },
    tabClick(tab, event) {
      let panName = tab.paneName
      if (panName == '1') {
        this.queryParams.payState = 0
      } else if (panName == '2') {
        this.queryParams.payState = 1
      } else if (panName == '3') {
        this.queryParams.payState = 2
      } else {
        this.queryParams.payState = null
      }
      this.getList()
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateFeApartmentCancelBill(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addFeApartmentCancelBill(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除公寓退租账单编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delFeApartmentCancelBill(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('life/feApartmentCancelBill/export', {
        ...this.queryParams
      }, `life_feApartmentCancelBill.xlsx`)
    }
  }
};
</script>
